#include "vlc_player.h"
#include <QDebug>
#include<QFileDialog>
#include<QInputDialog>
#include<QPushButton>
#include<QVBoxLayout>
#include<VLCQtCore/Audio.h>
#include<VLCQtCore/Common.h>
#include<VLCQtCore/Instance.h>
#include<VLCQtCore/Media.h>
#include<VLCQtCore/MediaPlayer.h>
#include<VLCQtWidgets/WidgetVideo.h>
#include"vodlistwgt.h"

VLC_player::VLC_player(QWidget *parent)
    : QWidget(parent)
    ,_media(nullptr)
    ,curUrl("")
{
    setFixedSize(900,550);
            QVBoxLayout* layout = new QVBoxLayout(this);

    //创建播放窗口
    _video = new VlcWidgetVideo(this);
    _vlcInstance = new VlcInstance(VlcCommon::args(),this);
    _player = new VlcMediaPlayer(_vlcInstance);
    _audio = new VlcAudio(_player);

    //设置默认音量大小
    _audio->setVolume(50);
    _player->setVideoWidget(_video);
    _video->setMediaPlayer(_player);

    //连接vlcmediplayer的timechanged，更新进度条
    connect(_player,&VlcMediaPlayer::timeChanged,this,[this](int value){
        emit TimeChanged(value);
    });

    _vodlistWgt = new VodListWgt(this);
    //创窗口分割器
    _spliter = new QSplitter(Qt::Horizontal,this);
    _spliter->addWidget(_video);
    _spliter->addWidget(_vodlistWgt);
    //设置窗口占比
    int totalWidth;
    _spliter->setSizes({totalWidth *4/5,totalWidth / 5});

    // 将分割器添加到主要布局

    layout->addWidget(_spliter);
    setLayout(layout);
}
//vlc_qt库
VLC_player::~VLC_player()
{
    delete  _audio;
    delete  _player;
    delete  _media;
    delete  _vlcInstance;
}

void VLC_player::OpenUrl(const QString url)
{

}

void VLC_player::onParsedChanged(bool status)
{

}

void VLC_player::onBuffering(float newCaChe)
{

}

void VLC_player::HandleControlSigna(const QVariant &data)
{

}
